import java.util.*;

/**
 * @author LKQ
 * @date 2022/4/3 14:08
 * @description hashMap
 */
public class Solution {
    public static void main(String[] args) {

    }
    public List<List<Integer>> findWinners(int[][] matches) {
        List<List<Integer>> ans = new ArrayList<>();
        Set<Integer> join = new HashSet<>();
        Map<Integer, Integer> map = new HashMap<>();
        for (int[] ma: matches) {
            join.add(ma[0]);
            join.remove(ma[1]);
            // 输掉的场次
            map.put(ma[1], map.getOrDefault(ma[1], 0) + 1);
        }
        List<Integer> an1 = new ArrayList<>(join);
        List<Integer> an2 = new ArrayList<>();
        for (Map.Entry<Integer, Integer> entry: map.entrySet()) {
            if (entry.getValue() == 1) {
                an2.add(entry.getKey());
            }
        }
        Collections.sort(an1);
        Collections.sort(an2);
        ans.add(an1);
        ans.add(an2);
        return ans;
    }
}
